package com.woniuxy.goods.controller;

import com.woniuxy.comments.entity.Goods;
import com.woniuxy.comments.util.CustomPage;
import com.woniuxy.comments.util.JWTUtil;
import com.woniuxy.comments.util.ResponseResult;
import com.woniuxy.goods.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;

/**
 * @Author Liu Tao
 * @Date 2023 05 15 15 41
 **/
@Slf4j
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    @GetMapping("/findAll/{page}/{size}")
    public ResponseResult<CustomPage<List<Goods>>> findByUid(@PathVariable("page") int page, @PathVariable("size") int size){
        return goodsService.findAll(page, size);
    }

    @GetMapping("/findById/{id}")
    public ResponseResult<Goods> findById(@PathVariable("id") int id){
        System.out.println(id);
        //
        return goodsService.findById(id);
    }
    @PutMapping("/updateByState/{id}")
    public ResponseResult<Boolean> update(@PathVariable("id") int id){
        return goodsService.updateByState(id);
    }

    @PutMapping("/add")
    public ResponseResult<Boolean> add(@RequestBody Goods goods){
        return goodsService.add(goods);
    }


    @PutMapping("/update")
    public ResponseResult<Boolean> update(@RequestBody Goods goods){
        return goodsService.update(goods);
    }



}
